POV-Ray : Newsgroups : povray.newusers : How to use #Macro like a function ? : Re: How to use #Macro like a function ? Server Time
5 Jul 2024 04:30:05 EDT (-0400)
  Re: How to use #Macro like a function ?  
From: clipka
Date: 29 Jun 2010 16:09:49
Message: <4c2a530d$1@news.povray.org>
Am 29.06.2010 21:37, schrieb Gyscos:
> Wow, I understand what didn't work...
> Well, partly...
>
> I used the macro in a declare :
>
> #declare MyVar = MyMacro(MyStuff);
>
> But POV-Ray parsed the macro and found some #if and #else BEFORE the expected
> semi-colon...
>
> :-/
>
> So I have to put the semi-colon IN the macro, and not in the #declare line...
> :(
>
> I think I'll use extra arguments to return the value instead...

This one will do:

   #macro MyMacro(arg)
     #if (arg > 1)
       #local RetVal = 5;
     #else
       #local RetVal = 10;
     #end
     RetVal
   #end

Note that the value to be returned is stored in a local variable first, 
which is then "returned" at the very end of the macro.

Extra arguments as return values are pretty cumbersome, as you'll always 
have to make sure that the respective variable is defined properly 
before being passed to (and back from) the macro.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.